package com.anonymous.util;

import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.Socket;
import java.security.NoSuchAlgorithmException;
import java.util.Arrays;

import javax.crypto.NoSuchPaddingException;
import javax.crypto.SecretKey;

import com.anonymous.message.ErrorMsg;
import com.anonymous.message.Message;
import com.anonymous.message.SecureMessage;
import com.anonymous.message.SecureObject;

public class NetworkUtils {
	public NetworkUtils(){
	}



	// send object to socket in unsecure mode
	public void send(Object obj, Socket socket) throws Exception {

		ObjectOutputStream out = new ObjectOutputStream(
				socket.getOutputStream());
		out.writeObject(obj);

	}

	// receive object from socket
	public Message receive(Socket socket) throws IOException, ClassNotFoundException {
		ObjectInputStream in;
		Message receivedMsg;

		if (socket.isClosed()) {
			return null;
		}

		in = new ObjectInputStream(socket.getInputStream());
		receivedMsg = (Message) in.readObject();
		return receivedMsg;
	}

}
